package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;



import com.ruoyi.zhgd.enums.SysStationType;
import com.ruoyi.zhgd.domain.NSysStation;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;

import com.ruoyi.zhgd.dto.SysStationDto;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NSysStationVo;
import com.ruoyi.zhgd.domain.bo.NSysStationBo;
import com.ruoyi.zhgd.service.INSysStationService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拌合楼
 *
 * @author zyb
 * @date 2023-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/sysStation")
public class NSysStationController extends BaseController {

    private final INSysStationService iNSysStationService;

    /**
     * 查询拌合楼列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NSysStationVo> list(NSysStationBo bo, PageQuery pageQuery) {
        return iNSysStationService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询拌合楼列表
     */
    @SaCheckLogin
    @GetMapping("/listSelect")
    public R<List<NSysStationVo>> listSelect(NSysStationBo bo) {
        return iNSysStationService.listSelect(bo);
    }

    /**
     * 获取拌和楼列表
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/allList")
    public List<NSysStation> allList(NSysStationBo bo) {
        return iNSysStationService.allList(bo);
    }

    /**
     * 导出拌合楼列表
     */
    @SaCheckLogin
    @Log(title = "拌合楼", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NSysStationBo bo, HttpServletResponse response) {
        List<NSysStationVo> list = iNSysStationService.queryList(bo);
        ExcelUtil.exportExcel(list, "拌合楼", NSysStationVo.class, response);
    }

    /**
     * 获取拌合楼详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NSysStationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iNSysStationService.queryById(id));
    }

    /**
     * 新增拌合楼
     */
    @SaCheckLogin
    @Log(title = "拌合楼", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NSysStation bo) {
        return toAjax(iNSysStationService.insertByBo(bo));
    }

    /**
     * 修改拌合楼
     */
    @SaCheckLogin
    @Log(title = "拌合楼", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NSysStation bo) {
        return toAjax(iNSysStationService.updateByBo(bo));
    }

    /**
     * 删除拌合楼
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "拌合楼", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iNSysStationService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
    * 获取水稳拌合楼列表
    * @author cj
    * @date 2023/10/8 10:00
    * @return
    **/
    @SaCheckLogin
    @GetMapping("/cementList")
    public R<List<NSysStation>> cementList(@RequestParam Map<String, Object> params) {
        params.put("type", SysStationType.CEMENT.getValue());
        List<NSysStation> list = iNSysStationService.list(params);
        return R.ok(list);
    }

    /**
     * 查询全部
     * @param params
     * @return
     */
    @SaCheckLogin
    @GetMapping("/cements")
    public R<List<NSysStation>> cements(@RequestParam Map<String, Object> params) {
        List<NSysStation> list = iNSysStationService.cements(params);
        return R.ok(list);
    }


    @SaCheckLogin
    @GetMapping("/sysStationList")
    public R sysStationList(@RequestParam Map<String, Object> params,
                            @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                            @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils pageUtils = iNSysStationService.sysStationList(new Query(paramMap).getPage(), params);
        return R.ok(pageUtils);
    }

    @GetMapping("/sysStationType")
    public List<SysStationDto> sysStationType(){
        return iNSysStationService.sysStationType();
    }

    /**
     * 沥青拌合楼列表
     * @return
     */
    @GetMapping("/asphaltList")
    public R<List<NSysStation>> asphaltList(@RequestParam Map<String, Object> params){
        params.put("type", SysStationType.ASPHALT.getValue());
        return R.ok(iNSysStationService.list(params));
    }


}
